package edu.nf.exam.dao.impl;

import edu.nf.exam.dao.MessageInfoDao;
import edu.nf.exam.entity.MessageInfo;
import edu.nf.exam.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Author : QYM
 * @create 2021/6/17
 * 消息信息表--接口实现类
 */
public class MessageInfoDaoImpl implements MessageInfoDao {
    /**
     * 查询所有消息
     * @param messageInfo
     * @return
     */
    @Override
    public List<MessageInfo> selectAll(MessageInfo messageInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<MessageInfo> list = sqlSession.getMapper(MessageInfoDao.class).selectAll(messageInfo);
        sqlSession.close();
        return list;
    }

    /**
     * 修改
     * @param messageInfo
     * @return
     */
    @Override
    public int update(MessageInfo messageInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        int r = sqlSession.getMapper(MessageInfoDao.class).update(messageInfo);
        sqlSession.close();
        return r;
    }

    /**
     * 添加
     * @param messageInfo
     * @return
     */
    @Override
    public int add(MessageInfo messageInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        int r = sqlSession.getMapper(MessageInfoDao.class).add(messageInfo);
        sqlSession.close();
        return r;
    }

    /**
     * 分页查询所有消息
     * @param sendUserName
     * @param receiveUserName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<MessageInfo> selectByPage(String sendUserName, String receiveUserName, Integer pageNum, Integer pageSize) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<MessageInfo> list = sqlSession.getMapper(MessageInfoDao.class).selectByPage(sendUserName,receiveUserName,pageNum,pageSize);
        sqlSession.close();
        return list;
    }
}
